﻿using System;
using System.Linq;
using System.Reflection;

namespace MicroMVVM
{
    /// <summary>
    /// This class represents a set of helpers which are used internally by MicroMVVM.
    /// </summary>
    internal static class InternalHelpers
    {
        /// <summary>
        /// Attempts to retrieve the attributes.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="memberInfo"></param>
        /// <param name="customAttribute"></param>
        /// <returns></returns>
        internal static bool TryGetAttribute<T>(MemberInfo memberInfo, out T customAttribute) where T : Attribute
        {
            var attributes = memberInfo.GetCustomAttributes(typeof(T), false).FirstOrDefault();

            customAttribute = (attributes == null) ? null : attributes as T;

            return (customAttribute != null);
        }
    }
}